﻿Imports System.Data.SqlClient

Public Class FormVendorEditor

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        If txtVendorId.Text = "" Then

            Dim cn As New SqlConnection
            cn.ConnectionString = "server=.;uid=sa;pwd=123;database=SaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand
            cmd.Connection = cn
            cmd.CommandText = "INSERT INTO	Vendor VALUES(N'" & txtVendorName.Text & "',N'" & txtPhone.Text & "',N'" & txtAddress.Text & " ',1)"
            cmd.ExecuteNonQuery()
        Else
            Dim cn As New SqlConnection
            cn.ConnectionString = "server=.;uid=sa;pwd=123;database=SaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand
            cmd.Connection = cn
            cmd.CommandText = "UPDATE Vendor SET VendorName=N'" & txtVendorName.Text & "',Phone=N'" & txtPhone.Text & "',Address=N'" & txtAddress.Text & "'WHERE VendorId=" & txtVendorId.Text
            cmd.ExecuteNonQuery()
        End If
        
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub FormVendorEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class


